﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using CustomsSystem.BLL;
using CustomsSystem.Model;
using Maticsoft.Common;
namespace WEB.password
{
    public partial class UserPasswordChange : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CustomsSystem.Model.Users myUsers = new CustomsSystem.Model.Users();
            if (!Page.IsPostBack)
            {
                myUsers.UserName = Session["UserName"].ToString();
                UserName.Text = myUsers.UserName;
            }
        }

        protected void btnChange_Click(object sender, EventArgs e)
        {
            CustomsSystem.Model.password_change model = new CustomsSystem.Model.password_change();
            ChangeManage changeManage = new ChangeManage();
            model.UserName = UserName.Text.Trim();
            model.OldPassWord =stringpro .md5 ( OldPassWord.Text.Trim());
            model.NewPassWord1 =stringpro .md5 ( NewPassWord1.Text.Trim());
            model.NewPassWord2 = stringpro .md5 (NewPassWord2.Text.Trim());
            if (model.OldPassWord == "" && model.NewPassWord1 == "" && model.NewPassWord2 == "")
            {
                Response.Write("<script>alert('请输入密码');</script>");
            }
            else
            {
                if (changeManage.Judge(model) == true)
                {
                    if (model.NewPassWord1 == model.OldPassWord)
                    {
                        Response.Write("<script>alert('您输入的旧密与新密码一致，无须更改密码')</script>");
                    }
                    else
                    {
                        if (changeManage.UserChange(model) == true)
                        {
                            Response.Write("<script>alert('更改密码成功')</script>");
                        }
                        else
                        {
                            Response.Write("<script>alert('原密码输入有误，请重新输入')</script>");
                        }
                    }
                }
                else
                {
                    Response.Write("<script>alert('两次输入的密码不一致，请重新输入')</script>");
                }
            }
        }
    }
}